package com.jeesite.modules.kj.utils;

import com.jeesite.common.utils.SpringUtils;
import com.jeesite.modules.kj.entity.KjMember;
import com.jeesite.modules.kj.entity.KjMemberIntegrals;
import com.jeesite.modules.kj.exception.FreezMemberException;
import com.jeesite.modules.kj.service.KjMemberIntegralsService;
import com.jeesite.modules.kj.service.KjMemberService;

public class KjMemberUtil {
    /**
     * 静态内部类，延迟加载，懒汉式，线程安全的单例模式
     */
    private static final class Static {
        private static KjMemberService kjMemberService = SpringUtils.getBean(KjMemberService.class);
        private static KjMemberIntegralsService kjMemberIntegralsService = SpringUtils.getBean(KjMemberIntegralsService.class);
    }

    public static KjMember getCurrentMember(String memberId) throws FreezMemberException {
        KjMember member = Static.kjMemberService.get(memberId);
        if(member != null && member.getStatus().equals(KjMember.STATUS_FREEZE)){
            throw new FreezMemberException("用户被冻结,请联系管理员");
        }
        return member;
    }

    public static KjMemberIntegrals getMemberIntegrals(KjMember member){
        return Static.kjMemberIntegralsService.findByMemberId(member.getId());
    }
}
